<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>授权码回调处理</title>
    <script src="./AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
    <script src="./AmazeUI-2.4.2/assets/js/amazeui.min.js"></script>
    <!--引入公共的js-->
    <script src="js/plugings/vue/dist/vue.min.js"></script>
    <script src="js/plugings/axios/dist/axios.min.js"></script>
    <script src="js/commons.js"></script>
</head>
<body>
<div id="app">{{message}}</div>

</body>
<script>
    new Vue({
        el:"#app",
        data:{
            message:"页面跳转中..."
        },
        methods:{
            getParamByUrl(url) {
                var theRequest = new Object();
                var index = url.indexOf("?");
                if (index != -1) {
                    var str = url.substr(index + 1);
                    strs = str.split("&");
                    for (var i = 0; i < strs.length; i++) {
                        theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
                    }
                }
                return theRequest;
            }
        },
        mounted(){
            let param = this.getParamByUrl(location.href);
            // console.log(param);
            this.$http.post("/wechat/login",param).then(res=>{
                if(res.data.success){
                    // 对象转换成json字符串JSON.stringify()
                    localStorage.setItem("token",res.data.resultObj.token);
                    localStorage.setItem("logininfo",JSON.stringify(res.data.resultObj.logininfo));
                    location.href="index.html"
                }else{
                    location.href=res.data.resultObj;
                }
            })
        }
    });
</script>
</html>